import { createBrowserRouter, Navigate } from 'react-router-dom'
import { lazy, Suspense } from "react";
import App from '../App'
import Message from '../Components/Message'
import Login from '../Components/Login'
import Zhu from '../Components/Zhu'
import Yzm from '../Components/Yzm'
import Xinxi from '../Components/Xinxi'
import Shou from '../Components/Shou'
import HomePage from '../Components/HomePage'
import Z_cate from '../Components/Z_cate'
import SouSuo from '../Components/SouSuo'
import Adddongtai from '../Components/Adddongtai'
import Search from '../Components/Search'
import Position from '../Components/Position'
import Z_xiang from '../Components/Z_xiang'
import Chat from '../Components/Chat'
import Lable from "../Components/Dong_My/Lable";
import Send from "../Components/Dong_My/SendMessage";
const My = lazy(() => import("../Components/Dong_My/My.jsx"));
const Update_My = lazy(() => import("../Components/Dong_My/Update_My.jsx"));
const Set = lazy(() => import("../Components/Dong_My/Set.jsx"));
const Update_password = lazy(() =>
    import("../Components/Dong_My/Update_password.jsx")
);
const My_info_desc = lazy(() =>
    import("../Components/Dong_My/My_info_desc.jsx")
);
const Auth = (props) => {
    let Add=props.children.type
    if (sessionStorage.getItem("accessToken") &&
        sessionStorage.getItem("refreshToken")) {
            return <Add></Add>
    }else{
        return <Navigate to={'/login'}></Navigate>
    }
}
// import Cs from '../Components/lf_cs'
const router = createBrowserRouter([
    // {path:'/cs',element:<Cs></Cs>},
    { path: '/search', element: <Search></Search> },
    { path: '/login', element: <Login></Login> },
    { path: '/zhu', element: <Zhu></Zhu> },
    { path: '/yzm', element: <Yzm></Yzm> },
    { path: '/xin', element: <Xinxi></Xinxi> },
    { path: '/shou', element: <Shou></Shou> },
    { path: '/position', element: <Position></Position> },
    { path: '/xiang', element: <Z_xiang></Z_xiang> },
    { path: '/chat', element: <Chat></Chat> },
    {
        path: "/update_password",
        element: (
            <Suspense fallback={<div>Loading...</div>}>
                <Update_password />
            </Suspense>
        ),
    },
    {
        path: "/set",
        element: (
            <Suspense fallback={<div>Loading...</div>}>
                <Set />
            </Suspense>
        ),
    },

    {
        path: "/update_my",
        element: (
            <Suspense fallback={<div>Loading...</div>}>
                <Update_My />
            </Suspense>
        ),
    },
    {
        path: "/my_info_desc",
        element: (
            <Suspense fallback={<div>Loading...</div>}>
                <My_info_desc />
            </Suspense>
        ),
    },
    { path: "/lable", element: <Lable /> },
    { path: "/send", element: <Send /> },
    {
        path: '/', element: <Auth><App></App></Auth>,
        children: [
            {
                path: "/my",
                element: (
                    <Suspense fallback={<div>Loading...</div>}>
                        <My />
                    </Suspense>
                ),
            },
            { path: '/cate', element: <Z_cate></Z_cate> },
            { path: "/home", element: <HomePage></HomePage> },
            { path: '/sou', element: <SouSuo></SouSuo> },
            { path: '/add', element: <Adddongtai></Adddongtai> },
            {path:'/message',element:<Message></Message>},
            {path:'/chat',element:<Chat></Chat>},
            { path: '/message', element: <Message></Message> }
        ]
    }])

export default router